package com.chuangjiangx.member.basic.ddd.application;

import com.chuangjiangx.member.score.ddd.application.command.CreatePayGiftCardRuleCommand;
import com.chuangjiangx.member.score.ddd.application.command.ModifyPayGiftCardRuleCommand;
import com.chuangjiangx.member.coupon.ddd.domain.model.MbrPayGiftCardRule;
import com.chuangjiangx.member.coupon.ddd.domain.service.MbrPayGiftCardDomainService;
import com.chuangjiangx.member.coupon.ddd.domain.model.GetChannelEnum;
import com.chuangjiangx.member.coupon.ddd.domain.model.MbrPayGiftCardWxStatusEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @Auther: YZJ
 * @Date: 2018/9/3 14:48
 * @Description:支付即会员规则
 */
@Service
public class MbrPayGiftCardRuleApplication {

    private final MbrPayGiftCardDomainService mbrPayGiftCardDomainService;

    @Autowired
    public MbrPayGiftCardRuleApplication(MbrPayGiftCardDomainService mbrPayGiftCardDomainService) {
        this.mbrPayGiftCardDomainService = mbrPayGiftCardDomainService;
    }

    /**
     * 新增规则
     *
     * @param command
     */
    public void createPayGiftCardRule(CreatePayGiftCardRuleCommand command) {
        MbrPayGiftCardRule mbrPayGiftCardRule = new MbrPayGiftCardRule(command.getMerchantId(),null, command.getBeginTime(), command.getEndTime(), command.getLeastCost(), GetChannelEnum.fromCodeList(command.getGetChannelList()), MbrPayGiftCardWxStatusEnum.UNSET, new Date(), new Date());
        mbrPayGiftCardDomainService.createRule(mbrPayGiftCardRule);
    }

    /**
     * 修改规则
     */
    public void updatePayGiftCardRule(ModifyPayGiftCardRuleCommand command) {
        mbrPayGiftCardDomainService.updatePayGiftCard(command);
    }
}
